package com.dlut.java4;

import java.util.Scanner;

/**
 * @Author: LiuHeng
 * @Description:
 * @Date: 2022-09-22 8:56
 */
public class T0922_MaYi {

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] num1 = new int[(n * n + 1) /2];
        int[] num2 = new int[n * n / 2];
        num1[0] = 1;
        num2[0] = 2;
        for (int i = 1; i < num1.length; i++) {
            num1[i] = num1[i-1] + 2;
        }
        for (int i = 1; i < num2.length; i++) {
            num2[i] = num2[i-1] + 2;
        }
        int point1=0, point2=0;
        if (n % 4 == 2){
            System.out.println(-1);
            return;
        }else if (n % 4 == 0){
            for (int i = 0; i < n / 4; i++) {
                for (int j = 0; j < n / 2; j++) {
                    System.out.print(num1[point1++] + " ");
                    System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j < n; j++) {
                    System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j < n / 2; j++) {
                    System.out.print(num1[point1++] + " ");
                    System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j < n; j++) {
                    System.out.print(num1[point1++] + " ");
                }
                System.out.println();
            }
        }else if (n % 4 == 1){
            for (int i = 0; i < n / 4; i++) {
                for (int j = 0; j <= n / 2; j++) {
                    System.out.print(num1[point1++] + " ");
                    if (j != n/2)
                        System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j < n; j++) {
                    System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j <= n / 2; j++) {
                    System.out.print(num2[point2++] + " ");
                    if (j != n/2)
                        System.out.print(num1[point1++] + " ");

                }
                System.out.println();
                for (int j = 0; j < n; j++) {
                    System.out.print(num1[point1++] + " ");
                }
                System.out.println();
            }
            for (int j = 0; j <= n / 2; j++) {
                System.out.print(num1[point1++] + " ");
                if (j != n/2 )
                    System.out.print(num2[point2++] + " ");
            }
        }else if (n % 4 == 3){
            for (int i = 0; i < n / 4; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(num1[point1++] + " ");
                }
                System.out.println();
                for (int j = 0; j <= n / 2; j++) {
                    System.out.print(num1[point1++] + " ");
                    if (j != n/2)
                        System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j < n; j++) {
                    System.out.print(num2[point2++] + " ");
                }
                System.out.println();
                for (int j = 0; j <= n / 2; j++) {
                    System.out.print(num2[point2++] + " ");
                    if (j != n/2)
                        System.out.print(num1[point1++] + " ");

                }
                System.out.println();

            }
            for (int j = 0; j < n; j++) {
                System.out.print(num1[point1++] + " ");
            }
            System.out.println();
            for (int j = 0; j <= n / 2; j++) {
                System.out.print(num1[point1++] + " ");
                if (j != n/2 )
                    System.out.print(num2[point2++] + " ");
            }
            System.out.println();
            for (int j = 0; j < n; j++) {
                System.out.print(num2[point2++] + " ");
            }
            System.out.println();
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        String k = in.nextLine();
        int n = line.length();
        int lenK = k.length();
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (i + lenK <= n){
                String substring = line.substring(i, i + lenK);
                if (substring.compareTo(k) < 0){
                    count += lenK;
                }else {
                    count += lenK - 1;
                }
            }else {
                count += n - i;
            }
        }
        System.out.println(count);
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        for (int i = 0; i < q; i++) {
            int op = in.nextInt();
            int k = in.nextInt();
            int x = in.nextInt();
            if (op == 1){
                nums[k-1] = x;
            }else {
                int count = search(nums, k, x);
                System.out.println(count);
            }
        }
    }

    private static int search(int[] nums, int k, int x) {
        int count = 0;
        for (int i = 0; i < k; i++) {
            if (nums[i] == x){
                count++;
            }
        }
        return count;
    }
}
